import pictureShuffling from '../banner/index.vue'
import intervalComponent from '../interval-component/index.vue'
import floorTitleComponent from '../floor-title/index.vue'
import goodsList from '../goods-list/index.vue'
import hotSpotComponent from '../hot-spot-component/index.vue'
import storeListComponent from '../store-list/index.vue'
import limitedSkillComponent from '../limited-skill-component/index.vue'
import discountCouponComponent from '../discount-coupon-component/index.vue'
import goodsModuleComponentOne from '../goods-module-one/index.vue'
import goodsModuleComponentTwo from '../goods-module-two/index.vue'
import goodsModuleComponentThree from '../goods-module-three/index.vue'
import goodsModuleComponentFour from '../goods-module-four/index.vue'
import goodsModuleComponentFive from '../goods-module-five/index.vue'

// 组件的配置
export const configComponentList = [
  {
    type: 'picture_by',
    components: shallowRef(pictureShuffling),
    rightConfigMessage: {}
  },
  {
    type: 'auxiliary_interval',
    components: shallowRef(intervalComponent),
    rightConfigMessage: {}
  },
  {
    type: 'floor_title',
    components: shallowRef(floorTitleComponent),
    rightConfigMessage: {}
  },
  {
    type: 'goods_list',
    components: shallowRef(goodsList),
    rightConfigMessage: {}
  },
  {
    type: 'universal_hotspot',
    components: shallowRef(hotSpotComponent),
    rightConfigMessage: {} // 右边配置信息
  },
  {
    type: 'store_list',
    components: shallowRef(storeListComponent),
    rightConfigMessage: {}
  },
  {
    type: 'limited_skill',
    components: shallowRef(limitedSkillComponent),
    rightConfigMessage: {}
  },
  {
    type: 'discount_coupon',
    components: shallowRef(discountCouponComponent),
    rightConfigMessage: {}
  },
  {
    type: 'goods_module1',
    components: shallowRef(goodsModuleComponentOne),
    rightConfigMessage: {}
  },
  {
    type: 'goods_module2',
    components: shallowRef(goodsModuleComponentTwo),
    rightConfigMessage: {}
  },
  {
    type: 'goods_module3',
    components: shallowRef(goodsModuleComponentThree),
    rightConfigMessage: {}
  },
  {
    type: 'goods_module4',
    components: shallowRef(goodsModuleComponentFour),
    rightConfigMessage: {}
  },
  {
    type: 'goods_module5',
    components: shallowRef(goodsModuleComponentFive),
    rightConfigMessage: {}
  }
]

// 根据不同的类型进行跳转不同的页面
export function redirectPath (router, item) {
  const { link, type } = item.path
  let url = ''
  switch (type) {
    case '1': // 用户选择的是跳转到某个商品
      // eslint-disable-next-line no-case-declarations
      const newPage = router.resolve({ path: '/detail', query: { prodId: link } })
      window.open(newPage.href, '_blank', 'noopener,noreferrer')
      break
    case '2': // 用户选择的是跳转到分类
      if (Array.isArray(link)) { // 说明是三级分类
        router.push({
          path: '/list',
          query: {
            cpid: link[0].value,
            cid: link[1].value,
            thCid: link[2].value
          }
        })
      } else { // 否则就是一级分类
        router.push({
          path: '/shop-index',
          query: {
            sid: link.shopId,
            cid: link.categoryId
          }
        })
      }
      break
    case '3': // 用户选择的是跳转到店铺
      if (link !== '') {
        router.push({
          path: '/shop-index',
          query: {
            sid: link
          }
        })
      }
      break
    case '4': // 用户选择的是跳转到页面
      router.push({
        path: link
      })
      break
    case '5': // 用户选择的是跳转到微页面
      router.push({
        path: '/select-decorate',
        query: {
          renovationId: link[0],
          sid: link[1]
        }
      })
      break
    case '6': // 用户选择的是自定义链接
      url = link.url || link
      // eslint-disable-next-line no-case-declarations
      const reg1 = /^\//
      if (link.checked) {
        if (reg1.test(url)) { // 如果当前路径以 / 开头，就让他在店铺里面跳转
          const newUrl = router.resolve({ path: url })
          window.open(newUrl.href, '_blank', 'noopener,noreferrer')
        } else {
          window.open(url, '_blank', 'noopener,noreferrer')
        }
      } else if (reg1.test(url)) { // 如果当前路径以 / 开头，就让他在店铺里面跳转
        router.push({
          path: url
        })
      } else {
        window.location.href = url
      }
      break
    default:
      break
  }
}
